/*
 * (c) ralfoide, http://gamez.googlecode.com/, 2008
 * Project: gamez
 * License TBD
 */


package com.alfray.gamez.shape;

import javax.microedition.khronos.opengles.GL10;


//-----------------------------------------------

/**
 * The 3d square plate.
 */
public class Square extends Shape {

	/**
	 * Creates a square shape with 2 triangles.
	 * Flat on Z=0 plane, with X=[-0.5 => 0.5], Y=[-0.5, 0.5].
	 */
    public Square(Color color) {
        
        /* vertices in CW order:
         *   view from top:
         *   1 --- 2  0-1-2       
         *   |   / |
         *   |  /  |
         *   | /   |
         *   0 --- 3  0-2-3
         */
        final float vertices[] = {
               -0.5f, -0.5f,  0.0f,    // 0 (CW)
               -0.5f,  0.5f,  0.0f,    // 1
                0.5f,  0.5f,  0.0f,    // 2
                0.5f, -0.5f,  0.0f,    // 3
         };

        final short indices[] = {
        		0, 1, 2,
                0, 2, 3,
        };
        
        final float normals[] = {
                -1, -1,  0.0f,     // 0
                -1,  1,  0.0f,     // 1
                 1,  1,  0.0f,     // 2
                 1, -1,  0.0f,     // 3
        };
        
        final float textCoord[] = {
                 0,  0,     // 0
                 0,  1,     // 1
                 1,  1,     // 2
                 1,  0,     // 3
        };

        final float diffuse[] = getColor(color);

        setupBuffers(vertices, normals, diffuse, indices);
		setupTextBuffers(textCoord);
		setUseTextureUnit(0);
    }

    /**
     * Override drawTo rotate the object.
     */
    @Override
    public void drawTo(GL10 gl) {
        super.drawTo(gl);
    }

}

